package com.example.choupaiapp.main.activity.message;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.choupaiapp.R;
import com.example.choupaiapp.common.adapter.BaseAdapterHelper;
import com.example.choupaiapp.common.adapter.QuickAdapter;
import com.example.choupaiapp.common.constant.Contacts;
import com.example.choupaiapp.common.finalokgo.callback.Callback;
import com.example.choupaiapp.common.finalokgo.request.RequestType;
import com.example.choupaiapp.common.ui.activity.CommonActivity;
import com.example.choupaiapp.common.util.SharedPreferencesHelp;
import com.example.choupaiapp.common.util.Utils;
import com.example.choupaiapp.main.activity.find.FindDetailActivity;
import com.example.choupaiapp.main.activity.find.FindVideoDetailActivity;
import com.example.choupaiapp.main.activity.home.OtherInfoActivity;
import com.example.choupaiapp.main.bean.FindDetailBean;
import com.example.choupaiapp.main.bean.MessageRemindBean;
import com.example.choupaiapp.main.bean.SendCodeBean;
import com.example.choupaiapp.main.bean.UserInfoBean;
import com.example.choupaiapp.main.bean.VideoListBean;
import com.example.choupaiapp.main.constant.Config;
import com.example.choupaiapp.main.constant.Url;
import com.gcssloop.widget.RCImageView;
import com.lzy.okgo.model.HttpParams;
import com.lzy.okgo.model.Response;
import com.mcxtzhang.swipemenulib.SwipeMenuLayout;
import com.scwang.smartrefresh.header.MaterialHeader;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnRefreshLoadMoreListener;

import org.greenrobot.eventbus.EventBus;

import butterknife.BindView;
import de.hdodenhof.circleimageview.CircleImageView;

/**
 * Created by ASUS on 2019/11/18.
 */

public class PraiseCommentFollowActivity extends CommonActivity implements OnRefreshLoadMoreListener {

    @BindView(R.id.listview)
    ListView listview;
    @BindView(R.id.refreshLayout)
    SmartRefreshLayout refreshLayout;
    private int operation;
    private QuickAdapter<MessageRemindBean.PageBean.ListBean> quickAdapter;
    private int pageNum = 1;
    private int pageSize = 20;
    @BindView(R.id.empty_img)
    ImageView empty_img;
    private UserInfoBean mUserInfoBean;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_praise_comment_follow);
    }

    @Override
    protected void initView() {

        refreshLayout.setOnRefreshLoadMoreListener(this);
        refreshLayout.setRefreshHeader(new MaterialHeader(context).setColorSchemeResources(R.color.common_color));
        mUserInfoBean = (UserInfoBean) SharedPreferencesHelp.getBean("userInfo");
        Bundle bundle = getIntent().getExtras();
        if (bundle != null) {
            operation = bundle.getInt("operation");
            if (operation == 2) {
                setTitle("赞过我的");
            } else if (operation == 3) {
                setTitle("评论我的");
            } else if (operation == 1) {
                setTitle("新的关注");
            }
        }

        quickAdapter = new QuickAdapter<MessageRemindBean.PageBean.ListBean>(context, R.layout.item_remind_child) {
            @Override
            protected void convert(BaseAdapterHelper helper, MessageRemindBean.PageBean.ListBean item) {
                SwipeMenuLayout swipemenulayout = helper.getView(R.id.swipemenulayout);
                Button delete = helper.getView(R.id.delete);
                delete.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        if (Utils.isDoubleClick()) {
                            return;
                        }
                        showDialog(context, "删除中...");
                        swipemenulayout.smoothClose();
                        HttpParams params = new HttpParams();
                        params.put("id", item.getId());
                        finalOkGo.requestHead(RequestType.POSTHEAD, Url.DELETE_REMIND_MESSAGE, params, Url.DELETE_REMIND_MESSAGE, new Callback<SendCodeBean>() {
                            @Override
                            public void onSuccess(SendCodeBean sendCodeBean) {
                                dismissDialog();
                                if (sendCodeBean.getCode() == Contacts.SUCCESS) {
                                    quickAdapter.remove(helper.getPosition());
                                    notifyDataSetChanged();
                                } else {
                                    if (sendCodeBean.getCode() == Contacts.TOKEN_EMPTY) {
                                    } else {
                                        showImageToas(sendCodeBean.getMsg());
                                    }
                                }
                            }

                            @Override
                            public void onError(Response response) {
                                super.onError(response);
                                dismissDialog();
                            }
                        });
                    }
                });

                helper.setText(R.id.description, item.getMessage());

                RCImageView photo = helper.getView(R.id.photo);
                TextView follow = helper.getView(R.id.follow);
                RelativeLayout photo_rl = helper.getView(R.id.photo_rl);
                RelativeLayout follow_rl = helper.getView(R.id.follow_rl);
                View follow_tip = helper.getView(R.id.follow_tip);
                View photo_tip = helper.getView(R.id.photo_tip);
                if (operation == 1) {

                    CircleImageView head_photo = helper.getView(R.id.head_photo);
                    helper.setText(R.id.name, item.getNickname());
                    Glide.with(context)
                            .load(item.getAvatar() + Config.IMAGE_LIM)
                            .dontAnimate()
                            .placeholder(R.mipmap.icon_no_head)
                            .into(head_photo);

                    head_photo.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            if (Utils.isDoubleClick()) {
                                return;
                            }
                            Bundle bundle1 = new Bundle();
                            bundle1.putString("userId", item.getByUserId() + "");
                            bundle1.putString("userName", item.getNickname());
                            startActivity(OtherInfoActivity.class, bundle1);
                            item.setStatus(1);
                            quickAdapter.notifyDataSetChanged();
                        }
                    });

                    photo_rl.setVisibility(View.GONE);
                    follow_rl.setVisibility(View.VISIBLE);

                    if (item.getIsAttention() == 0) {
                        follow.setText("关注TA");
                        follow.setBackgroundResource(R.drawable.shape_yellow_oval);
                        follow.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                if (Utils.isDoubleClick()) {
                                    return;
                                }
                                showDialog(context, "关注中...");
                                finalOkGo.requestHead(RequestType.GETHEAD, Url.FOLLOW_OTHER + item.getByUserId(), null, Url.FOLLOW_OTHER, new Callback<SendCodeBean>() {
                                    @Override
                                    public void onSuccess(SendCodeBean sendCodeBean) {
                                        dismissDialog();
                                        if (sendCodeBean.getCode() == Contacts.SUCCESS) {
                                            item.setIsAttention(1);
                                            quickAdapter.notifyDataSetChanged();
                                        } else {
                                            if (sendCodeBean.getCode() == Contacts.TOKEN_EMPTY) {
                                            } else {
                                                showImageToas(sendCodeBean.getMsg());
                                            }
                                        }
                                    }

                                    @Override
                                    public void onError(Response<String> response) {
                                        super.onError(response);
                                        dismissDialog();
                                    }
                                });
                            }
                        });
                    } else {
                        follow.setText("相互关注");
                        follow.setBackgroundResource(R.drawable.shape_gray_oval);
                        follow.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                if (Utils.isDoubleClick()) {
                                    return;
                                }
                                showDialog(context, "取消关注...");
                                finalOkGo.requestHead(RequestType.GETHEAD, Url.CANCEL_FOLLOW + item.getByUserId(), null, Url.CANCEL_FOLLOW, new Callback<SendCodeBean>() {
                                    @Override
                                    public void onSuccess(SendCodeBean sendCodeBean) {
                                        dismissDialog();
                                        if (sendCodeBean.getCode() == Contacts.SUCCESS) {
                                            item.setIsAttention(0);
                                            quickAdapter.notifyDataSetChanged();
                                        } else {
                                            if (sendCodeBean.getCode() == Contacts.TOKEN_EMPTY) {
                                            } else {
                                                showImageToas(sendCodeBean.getMsg());
                                            }
                                        }
                                    }

                                    @Override
                                    public void onError(Response<String> response) {
                                        super.onError(response);
                                        dismissDialog();
                                    }
                                });
                            }
                        });
                    }

                    if (item.getStatus() == 0) {
                        follow_tip.setVisibility(View.VISIBLE);
                    } else {
                        follow_tip.setVisibility(View.INVISIBLE);
                    }
                } else {
                    if (operation == 3) {
                        if (item.getByUserId() == item.getAuthorId()) {
                            if (item.getAnonymity() == 1) {
                                CircleImageView head_photo = helper.getView(R.id.head_photo);
                                helper.setText(R.id.name, "匿名用户");
                                Glide.with(context)
                                        .load("")
                                        .dontAnimate()
                                        .error(R.mipmap.head_anonymous_orange)
                                        .into(head_photo);

                                head_photo.setOnClickListener(new View.OnClickListener() {
                                    @Override
                                    public void onClick(View view) {
                                        if (Utils.isDoubleClick()) {
                                            return;
                                        }
                                        item.setStatus(1);
                                        quickAdapter.notifyDataSetChanged();
//                                        Bundle bundle1 = new Bundle();
//                                        bundle1.putString("userId", item.getByUserId() + "");
//                                        bundle1.putString("userName", item.getNickname());
//                                        startActivity(OtherInfoActivity.class, bundle1);
                                    }
                                });
                            } else {
                                CircleImageView head_photo = helper.getView(R.id.head_photo);
                                helper.setText(R.id.name, item.getNickname());
                                Glide.with(context)
                                        .load(item.getAvatar() + Config.IMAGE_LIM)
                                        .dontAnimate()
                                        .placeholder(R.mipmap.icon_no_head)
                                        .into(head_photo);

                                head_photo.setOnClickListener(new View.OnClickListener() {
                                    @Override
                                    public void onClick(View view) {
                                        if (Utils.isDoubleClick()) {
                                            return;
                                        }
                                        Bundle bundle1 = new Bundle();
                                        bundle1.putString("userId", item.getByUserId() + "");
                                        bundle1.putString("userName", item.getNickname());
                                        startActivity(OtherInfoActivity.class, bundle1);
                                        item.setStatus(1);
                                        quickAdapter.notifyDataSetChanged();
                                    }
                                });
                            }
                        } else {
                            CircleImageView head_photo = helper.getView(R.id.head_photo);
                            helper.setText(R.id.name, item.getNickname());
                            Glide.with(context)
                                    .load(item.getAvatar() + Config.IMAGE_LIM)
                                    .dontAnimate()
                                    .placeholder(R.mipmap.icon_no_head)
                                    .into(head_photo);

                            head_photo.setOnClickListener(new View.OnClickListener() {
                                @Override
                                public void onClick(View view) {
                                    if (Utils.isDoubleClick()) {
                                        return;
                                    }
                                    Bundle bundle1 = new Bundle();
                                    bundle1.putString("userId", item.getByUserId() + "");
                                    bundle1.putString("userName", item.getNickname());
                                    startActivity(OtherInfoActivity.class, bundle1);
                                    item.setStatus(1);
                                    quickAdapter.notifyDataSetChanged();
                                }
                            });
                        }
                    } else {
                        CircleImageView head_photo = helper.getView(R.id.head_photo);
                        helper.setText(R.id.name, item.getNickname());
                        Glide.with(context)
                                .load(item.getAvatar() + Config.IMAGE_LIM)
                                .dontAnimate()
                                .placeholder(R.mipmap.icon_no_head)
                                .into(head_photo);

                        head_photo.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                if (Utils.isDoubleClick()) {
                                    return;
                                }
                                Bundle bundle1 = new Bundle();
                                bundle1.putString("userId", item.getByUserId() + "");
                                bundle1.putString("userName", item.getNickname());
                                startActivity(OtherInfoActivity.class, bundle1);
                                item.setStatus(1);
                                quickAdapter.notifyDataSetChanged();
                            }
                        });
                    }
                    helper.getView(R.id.item_ll).setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            if (Utils.isDoubleClick()) {
                                return;
                            }
                            if (item.getModule() == 2 || item.getModule() == 4) {
                                if(operation==2){
                                    if(item.getContentType()==1){
                                        Bundle bundle = new Bundle();
                                        bundle.putString("id", item.getContentId() + "");
                                        if(item.getCommentId()!=-1){
                                            bundle.putString("flag", "comment");
                                        }
                                        startActivity(FindDetailActivity.class, bundle);
                                    }else if(item.getContentType()==2){
                                        HttpParams params1 = new HttpParams();
                                        params1.put("id", item.getContentId());
                                        if (mUserInfoBean != null) {
                                            params1.put("userId", mUserInfoBean.getUser().getUserId());
                                        }
                                        finalOkGo.request(RequestType.POST, Url.FIND_DETAIL, params1, Url.FIND_DETAIL, new Callback<FindDetailBean>() {
                                            @Override
                                            public void onSuccess(FindDetailBean findDetailBean) {
                                                if (findDetailBean.getCode() == Contacts.SUCCESS) {
                                                    Bundle bundle = new Bundle();
                                                    VideoListBean videoListBean = new VideoListBean();
                                                    videoListBean.setVideoDownloadUrl(findDetailBean.getDiscover().getContent());
                                                    videoListBean.setCoverImgUrl(findDetailBean.getDiscover().getContent() + "?vframe/jpg/offset/1");
                                                    videoListBean.setTitle(findDetailBean.getDiscover().getTitle());
                                                    videoListBean.setComment_num(findDetailBean.getDiscover().getCommentSum());
                                                    videoListBean.setPraise_num(findDetailBean.getDiscover().getLikeSum());
                                                    videoListBean.setHeadPhoto(findDetailBean.getDiscover().getAvatar());
                                                    videoListBean.setNickName(findDetailBean.getDiscover().getNickname());
                                                    videoListBean.setTime(findDetailBean.getDiscover().getCreateTime());
                                                    videoListBean.setIsLike(findDetailBean.getDiscover().getIsLike());
                                                    videoListBean.setAnonymity(0);
                                                    videoListBean.setUserId(findDetailBean.getDiscover().getUserId());
                                                    videoListBean.setContentId(findDetailBean.getDiscover().getId());
                                                    videoListBean.setModule(2);
                                                    bundle.putSerializable("data", videoListBean);
                                                    bundle.putInt("videoId", findDetailBean.getDiscover().getId());
                                                    bundle.putString("flag", "mineVideo");
                                                    bundle.putString("categoriesId", findDetailBean.getDiscover().getCategoriesId()+"");
//                                            bundle.putInt("position", i);
                                                    startActivity(FindVideoDetailActivity.class, bundle);
                                                }
                                            }
                                        });
                                    }
                                }else if(operation==3){
                                    if(item.getContentType()==1){
                                        Bundle bundle = new Bundle();
                                        bundle.putString("id", item.getContentId() + "");
                                        if(item.getCommentId()!=-1){
                                            bundle.putString("flag", "comment");
                                        }
                                        startActivity(FindDetailActivity.class, bundle);
                                    }else if(item.getContentType()==2){
                                        HttpParams params1 = new HttpParams();
                                        params1.put("id", item.getContentId());
                                        if (mUserInfoBean != null) {
                                            params1.put("userId", mUserInfoBean.getUser().getUserId());
                                        }
                                        finalOkGo.request(RequestType.POST, Url.FIND_DETAIL, params1, Url.FIND_DETAIL, new Callback<FindDetailBean>() {
                                            @Override
                                            public void onSuccess(FindDetailBean findDetailBean) {
                                                if (findDetailBean.getCode() == Contacts.SUCCESS) {
                                                    Bundle bundle = new Bundle();
                                                    VideoListBean videoListBean = new VideoListBean();
                                                    videoListBean.setVideoDownloadUrl(findDetailBean.getDiscover().getContent());
                                                    videoListBean.setCoverImgUrl(findDetailBean.getDiscover().getContent() + "?vframe/jpg/offset/1");
                                                    videoListBean.setTitle(findDetailBean.getDiscover().getTitle());
                                                    videoListBean.setComment_num(findDetailBean.getDiscover().getCommentSum());
                                                    videoListBean.setPraise_num(findDetailBean.getDiscover().getLikeSum());
                                                    videoListBean.setHeadPhoto(findDetailBean.getDiscover().getAvatar());
                                                    videoListBean.setNickName(findDetailBean.getDiscover().getNickname());
                                                    videoListBean.setTime(findDetailBean.getDiscover().getCreateTime());
                                                    videoListBean.setIsLike(findDetailBean.getDiscover().getIsLike());
                                                    videoListBean.setAnonymity(0);
                                                    videoListBean.setUserId(findDetailBean.getDiscover().getUserId());
                                                    videoListBean.setContentId(findDetailBean.getDiscover().getId());
                                                    videoListBean.setModule(2);
                                                    bundle.putSerializable("data", videoListBean);
                                                    bundle.putInt("videoId", findDetailBean.getDiscover().getId());
                                                    bundle.putString("flag", "mineVideo");
                                                    bundle.putString("categoriesId", findDetailBean.getDiscover().getCategoriesId()+"");
//                                            bundle.putInt("position", i);
                                                    startActivity(FindVideoDetailActivity.class, bundle);
                                                }
                                            }
                                        });
                                    }
                                }else{
                                    if(item.getContentType()==1){
                                        Bundle bundle = new Bundle();
                                        bundle.putString("id", item.getContentId() + "");
                                        startActivity(FindDetailActivity.class, bundle);
                                    }else if(item.getContentType()==2){
                                        HttpParams params1 = new HttpParams();
                                        params1.put("id", item.getContentId());
                                        if (mUserInfoBean != null) {
                                            params1.put("userId", mUserInfoBean.getUser().getUserId());
                                        }
                                        finalOkGo.request(RequestType.POST, Url.FIND_DETAIL, params1, Url.FIND_DETAIL, new Callback<FindDetailBean>() {
                                            @Override
                                            public void onSuccess(FindDetailBean findDetailBean) {
                                                if (findDetailBean.getCode() == Contacts.SUCCESS) {
                                                    Bundle bundle = new Bundle();
                                                    VideoListBean videoListBean = new VideoListBean();
                                                    videoListBean.setVideoDownloadUrl(findDetailBean.getDiscover().getContent());
                                                    videoListBean.setCoverImgUrl(findDetailBean.getDiscover().getContent() + "?vframe/jpg/offset/1");
                                                    videoListBean.setTitle(findDetailBean.getDiscover().getTitle());
                                                    videoListBean.setComment_num(findDetailBean.getDiscover().getCommentSum());
                                                    videoListBean.setPraise_num(findDetailBean.getDiscover().getLikeSum());
                                                    videoListBean.setHeadPhoto(findDetailBean.getDiscover().getAvatar());
                                                    videoListBean.setNickName(findDetailBean.getDiscover().getNickname());
                                                    videoListBean.setTime(findDetailBean.getDiscover().getCreateTime());
                                                    videoListBean.setIsLike(findDetailBean.getDiscover().getIsLike());
                                                    videoListBean.setAnonymity(0);
                                                    videoListBean.setUserId(findDetailBean.getDiscover().getUserId());
                                                    videoListBean.setContentId(findDetailBean.getDiscover().getId());
                                                    videoListBean.setModule(2);
                                                    bundle.putSerializable("data", videoListBean);
                                                    bundle.putInt("videoId", findDetailBean.getDiscover().getId());
                                                    bundle.putString("flag", "mineVideo");
                                                    bundle.putString("categoriesId", findDetailBean.getDiscover().getCategoriesId()+"");
//                                            bundle.putInt("position", i);
                                                    startActivity(FindVideoDetailActivity.class, bundle);
                                                }
                                            }
                                        });
                                    }
                                }
                            } else if (item.getModule() == 0 || item.getModule() == 1) {
                                if (operation == 3) {
                                    Bundle bundle1 = new Bundle();
                                    bundle1.putString("flag", "comment");
                                    bundle1.putString("id", item.getContentId() + "");
                                    startActivity(ByIdDetailActivity.class, bundle1);
                                }else if(operation==2){
                                    Bundle bundle1 = new Bundle();
                                    bundle1.putString("id", item.getContentId() + "");
                                    if(item.getCommentId()!=-1){
                                        bundle1.putString("flag", "comment");
                                    }
                                    startActivity(ByIdDetailActivity.class, bundle1);
                                }else{
                                    Bundle bundle1 = new Bundle();
                                    bundle1.putString("id", item.getContentId() + "");
                                    startActivity(ByIdDetailActivity.class, bundle1);
                                }
                            }

                            item.setStatus(1);
                            quickAdapter.notifyDataSetChanged();
                        }
                    });
                    photo_rl.setVisibility(View.VISIBLE);
                    follow_rl.setVisibility(View.GONE);

                    if (item.getModule() == 1) {
                        if (item.getContentType() == 1) {
                            photo.setVisibility(View.VISIBLE);
                            Glide.with(context)
                                    .load(item.getImage() + "?vframe/jpg/offset/1")
                                    .dontAnimate()
                                    .placeholder(R.color.color_f3f3)
                                    .centerCrop()
                                    .into(photo);
                        } else if (item.getContentType() == 2) {
                            photo.setVisibility(View.VISIBLE);
                            Glide.with(context)
                                    .load(item.getImage().split("\\|")[0] + Config.IMAGE_LIM)
                                    .dontAnimate()
                                    .placeholder(R.color.color_f3f3)
                                    .centerCrop()
                                    .into(photo);
                        } else if (item.getContentType() == 3) {
                            photo.setVisibility(View.INVISIBLE);
//                            Glide.with(context)
//                                    .load("")
//                                    .dontAnimate()
//                                    .placeholder(R.color.color_f3f3)
//                                    .centerCrop()
//                                    .into(photo);
                        }
                    } else if (item.getModule() == 2) {
                        if (item.getContentType() == 1) {
                            photo.setVisibility(View.VISIBLE);
                            Glide.with(context)
                                    .load(item.getImage().split("\\|")[0] + Config.IMAGE_LIM)
                                    .dontAnimate()
                                    .placeholder(R.color.color_f3f3)
                                    .centerCrop()
                                    .into(photo);
                        } else if (item.getContentType() == 2) {
                            photo.setVisibility(View.VISIBLE);
                            Glide.with(context)
                                    .load(item.getImage() + "?vframe/jpg/offset/1")
                                    .dontAnimate()
                                    .placeholder(R.color.color_f3f3)
                                    .centerCrop()
                                    .into(photo);
                        } else if (item.getContentType() == 3) {
                            photo.setVisibility(View.INVISIBLE);
//                            Glide.with(context)
//                                    .load("")
//                                    .dontAnimate()
//                                    .placeholder(R.color.color_f3f3)
//                                    .centerCrop()
//                                    .into(photo);
                        }
                    }

                    if (item.getStatus() == 0) {
                        photo_tip.setVisibility(View.VISIBLE);
                    } else {
                        photo_tip.setVisibility(View.INVISIBLE);
                    }
                }
            }
        };

        listview.setAdapter(quickAdapter);
    }

    @Override
    protected void initData() {
        showDialog(context, null);
        HttpParams params = new HttpParams();
        params.put("operation", operation);
        params.put("page", pageNum++);
        params.put("limit", pageSize);
        finalOkGo.requestHead(RequestType.POSTHEAD, Url.MESSAGE_REMIND_LIST, params, Url.MESSAGE_REMIND_LIST, new Callback<MessageRemindBean>() {
            @Override
            public void onSuccess(MessageRemindBean messageRemindBean) {
                dismissDialog();
                if (messageRemindBean.getCode() == Contacts.SUCCESS) {
                    EventBus.getDefault().post("clearMessageRemind");
                    if (pageNum - 1 == 1) {
                        if (messageRemindBean.getPage().getList() == null || messageRemindBean.getPage().getList().size() == 0) {
                            empty_img.setVisibility(View.VISIBLE);
                            if (operation == 2) {
                                empty_img.setImageResource(R.mipmap.icon_no_praise_msg);
                            } else if (operation == 3) {
                                empty_img.setImageResource(R.mipmap.icon_no_comment);
                            } else if (operation == 1) {
                                empty_img.setImageResource(R.mipmap.icon_no_follow_msg);
                            }
                        } else {
                            empty_img.setVisibility(View.GONE);
                        }
                        quickAdapter.clear();
                        quickAdapter.addAll(messageRemindBean.getPage().getList());
                    } else {
                        quickAdapter.addAll(messageRemindBean.getPage().getList());
                    }
                    refreshLayout.finishRefresh();
                    refreshLayout.finishLoadMore();
                    quickAdapter.notifyDataSetChanged();

                    int pagecount;
                    if (messageRemindBean.getPage().getTotalCount() % pageSize == 0) {
                        pagecount = messageRemindBean.getPage().getTotalCount() / pageSize;
                    } else {
                        pagecount = messageRemindBean.getPage().getTotalCount() / pageSize + 1;
                    }

                    if (pageNum > pagecount) {
                        refreshLayout.setNoMoreData(true);
                        refreshLayout.finishLoadMoreWithNoMoreData();
                    } else {
                        refreshLayout.setNoMoreData(false);
                    }
                } else {
                    refreshLayout.finishRefresh();
                    refreshLayout.finishLoadMore();
                    if (messageRemindBean.getCode() == Contacts.TOKEN_EMPTY) {
                    } else {
                        showImageToas(messageRemindBean.getMsg());
                    }
                }
            }

            @Override
            public void onError(Response<String> response) {
                super.onError(response);
                dismissDialog();
                refreshLayout.finishRefresh();
                refreshLayout.finishLoadMore();
                if (pageNum - 1 == 1) {
                    empty_img.setVisibility(View.VISIBLE);
                    empty_img.setImageResource(R.mipmap.icon_no_net);
                }
            }
        });
    }

    @Override
    public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
        initData();
    }

    @Override
    public void onRefresh(@NonNull RefreshLayout refreshLayout) {
        pageNum = 1;
        initData();
    }
}
